﻿using Harmontronics.DataAccess.IOperate.Business;
using Harmontronics.Model.Common;
using Harmontronics.Model.Dto.Model;
using Harmontronics.Model.Entitys;
using Harmontronics.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Harmontronics.DataAccess.Operate.Business
{
    public class PlcSettingOperate : IPlcSettingOperate
    {
        private HcDbContext _db { get; set; }
        public PlcSettingOperate(HcDbContext db)
        {
            _db = db;
        }
        //查询所有
        public List<PlcSetting> GetAllPlcSettingList()
        {

            return _db.PlcSettings.ToList();
        }

        public PlcSetting GetPlcSettingById(string id)
        {
            return _db.PlcSettings.SingleOrDefault(i => i.PlcId == id);
        }

        public List<PlcSetting> GetPlcSettingByIdList(List<string> ids)
        {
            return _db.PlcSettings.Where(i => ids.Contains(i.PlcId)).ToList();
        }

        public void AddPlcSetting(PlcSetting entity)
        {
            _db.PlcSettings.Add(entity);
        }

        public void UpdatePlcSetting(PlcSetting entity)
        {
            _db.PlcSettings.Update(entity);
        }

        public void DeletePlcSetting(PlcSetting entity)
        {
            _db.PlcSettings.Remove(entity);
        }

        public void BatchDelPlcSetting(List<PlcSetting> entity)
        {
            _db.PlcSettings.RemoveRange(entity);

        }

        public List<PlcSetting> GetPlcSettingByIp(string ip)
        {
            return _db.PlcSettings.Where(i => i.Ip == ip).ToList();
        }
    }
}
